package lt.marsrutai.mobile.android.dao;

import java.io.IOException;
import java.net.UnknownHostException;

import lt.marsrutai.mobile.android.dao.exception.BackendException;
import lt.marsrutai.mobile.android.dao.exception.EmptyResponseException;
import lt.marsrutai.mobile.android.dao.exception.NoConnectivityException;
import lt.marsrutai.mobile.android.dao.exception.NoDataException;

import org.json.JSONException;


public class DaoExceptionMapper {
    public BackendException map(Exception ex) {
        if (ex instanceof EmptyResponseException) {
            return new NoDataException(ex);
        }
        else if (ex instanceof UnknownHostException) {
            return new NoConnectivityException(ex);
        }
        else if (ex instanceof JSONException) {
            return new BackendException(ex);
        }
        else if (ex instanceof IOException) {
            return new BackendException(ex);
        }
        else {
            return new BackendException(ex);
        }
    }
}
